
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AutoGear.BLL;
using ECommerce.Library.Mail;
using System.Collections.Specialized;


public partial class admin_customer_add : SiteAdminBasePage
{

    protected void Page_Load(object sender, EventArgs e)
    {
        uccResponseMessage.Visible = false;
        if (!Page.IsPostBack)
        {
            uccBillingState.DataBind();
            uccBillingCountry.DataBind();
            uccShippingState.DataBind();
            uccShippingCountry.DataBind();
        }
    }

    protected void Create_Click(object sender, EventArgs e)
    {
        try
        {
            this.Page.Validate();

            if (IsValid)
            {
                string LoginEmailAddress = tbxLoginEmailAddress.Text.Trim();
                if (!AutoGearSiteUser.IsUserExists(LoginEmailAddress))
                {
                    string firstName = tbxPersonalFirstName.Text;
                    string lastName = tbxPersonalLastName.Text;
                    DateTime dateOfBirth;
                    if (!DateTime.TryParse(tbxPersonalDateOfBirth.Text, out dateOfBirth))
                    {
                        uccResponseMessage.SetFailMessage("Incorrect date.");
                        uccResponseMessage.Visible = true;
                        return;
                    }
                    string emailAddress = tbxPersonalEmailAddress.Text;
                    Gender userGender;
                    if (rbtMale.Checked)
                    {
                        userGender = Gender.Male;
                    }
                    else
                    {
                        userGender = Gender.Female;
                    }
                    string userTelephoneNumber = tbxContactPhoneNumber.Text;
                    string userFaxNumber = tbxContactFaxNumber.Text;
                    string companyName = string.Empty;// tbxCompanyName.Text;
                    string companyTelephoneNumber = string.Empty; // tbxCompanyPhoneNumber.Text;
                    string companyFaxNumber = string.Empty;// tbxCompanyFaxNumber.Text;
                    AutoGear.BLL.Address billingAddress = new AutoGear.BLL.Address(tbxBillingFirstName.Text, tbxBillingLastName.Text, tbxBillingAddressLine1.Text, tbxBillingAddressLine2.Text, tbxBillingCity.Text, uccBillingState.SelectedItem.Text, uccBillingCountry.SelectedItem.Text, tbxBillingZipCode.Text, tbxBillingPhoneNumber.Text, string.Empty, tbxBillingEmailAddress.Text);
                    AutoGear.BLL.Address shippingAddress = new AutoGear.BLL.Address(tbxShippingFirstName.Text, tbxShippingLastName.Text, tbxShippingAddressLine1.Text, tbxShippingAddressLine2.Text, tbxShippingCity.Text, uccShippingState.SelectedItem.Text, uccShippingCountry.SelectedItem.Text, tbxShippingZipCode.Text, tbxShippingPhoneNumber.Text, string.Empty, tbxShippingEmailAddress.Text);
                    string loginEmailAddress = tbxLoginEmailAddress.Text;
                    string loginPassword = tbxLoginPassword.Text;
                    bool isActive = chkActiveUser.Checked;
                    CustomerUser customerUser = CustomerUser.Create(firstName, lastName, dateOfBirth, emailAddress, userGender, userTelephoneNumber, userFaxNumber, companyName, companyTelephoneNumber, companyFaxNumber, billingAddress, shippingAddress, isActive, loginEmailAddress, loginPassword,tbxAdminComment.Text.Trim());
                    if (customerUser != null)
                    {
                        //Email.SendRegistrationEmail(customerUser);
                        //Email.SendRegistrationEmailToAdmin(customerUser);
                        //Response.Redirect(AutoGear.BLL.CustomSiteMap.RegistrationSuccessful);
                        uccResponseMessage.SetSuccessMessage(AutoGearCommonMessage.CustomerAddSuccessful);
                        uccResponseMessage.Visible = true;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
                else
                {
                    uccResponseMessage.SetFailMessage(AutoGearCommonMessage.CustomerAddFailed);
                    uccResponseMessage.Visible = true;
                }
            }
        }
        catch (Exception ex)
        {
            uccResponseMessage.SetFailMessage(AutoGearCommonMessage.CustomerAddFailed);
            uccResponseMessage.Visible = true;
        }
    }
}

